﻿/*
NAILSUPERSTORE ® COMPANY
 
[HISTORY]
Created By  	: NGUYEN VAN TY
Created Date	: 23/02/2010
Modified By     :
Modified Date   :
Note            :

*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CommonTagTime;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
namespace CommonTagTime.DataAccess
{
    public class daoVideoCategory
    {
        public daoVideoCategory()
        {

        }
        public VideoCategoryCollection GetByCategoryId(int categoryId)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            VideoCategoryCollection items = new VideoCategoryCollection();
            try
            {
                para[0] = new SqlParameter(busVideoCategory.CategoryID, SqlDbType.Int);
                para[0].Value = categoryId;
                de = clsSQL.SPDataReader("VideoCategory_GetByCategoryID", para);
                while (de.Read())
                {
                    VideoCategory item = Load(de);
                    items.Add(item);
                }
                de.Close();
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoVideoCategory", "GetByCategoryId(int categoryId)", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }
            return items;
        }
        public VideoCategoryCollection GetByVideoId(int videoId)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            VideoCategoryCollection items = new VideoCategoryCollection();
            try
            {
                para[0] = new SqlParameter(busVideoCategory.VideoID, SqlDbType.Int);
                para[0].Value =videoId;
                de = clsSQL.SPDataReader("VideoCategory_GetByVideoId", para);
                while (de.Read())
                {
                    VideoCategory item = Load(de);
                    items.Add(item);
                }
                de.Close();                
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoVideoCategory", "CategoryCollection GetByVideoId(int videoId)", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }
            return items;
        }
        private VideoCategory Load(IDataReader de)
        {
            VideoCategory item = new VideoCategory();           
            item.CategoryID = clsConvert.DbToInt("CategoryID", de);
            item.VideoID = clsConvert.DbToInt("VideoID", de);           
            item.IsActive = clsConvert.DbToBoolean("IsActive", de);           
            return item;        
        }
        public bool DeleteByVideo(int videoID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];         
            try
            {
                para[0] = new SqlParameter(busVideoCategory.VideoID, SqlDbType.Int);
                para[0].Value = videoID;
                result = clsSQL.SPExecute("VideoCategory_DeleteByVideoId", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoVideoCategory", "DeleteByVideo(int videoID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }
        public bool Insert(VideoCategory objData)
        {
         
            int result=0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[3];        
            try
            {
                para[0] = new SqlParameter(busVideoCategory.CategoryID, SqlDbType.Int);
                para[0].Value =objData.CategoryID;
                para[1] = new SqlParameter(busVideoCategory.VideoID, SqlDbType.Int);
                para[1].Value = objData.VideoID;
                para[2] = new SqlParameter(busVideoCategory.ISACTIVE, SqlDbType.Bit);
                para[2].Value = objData.IsActive;
                result = clsSQL.SPExecute("VideoCategory_Insert", para);               

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoVideoCategory", "Insert(VideoCategory objData)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

    }
}
